﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using RT = Coolzon.Metadata.Runtime;

namespace Coolzon.UI.Core.Converters
{
    /// <summary>
    /// 适用于,border,margin,padding
    /// </summary>
    public class ThicknessConverter : ValueConverter
    {
        public object Convert(ConvertContext context, RT.Property property)
        {
            string thicknessStr = string.IsNullOrEmpty(property.ValueString) == false ? property.ValueString : property.ValueNode.GetAtrributeValue("Value");
            if(!string.IsNullOrEmpty(thicknessStr))
            {
                System.Windows.ThicknessConverter tc = new System.Windows.ThicknessConverter();
                return tc.ConvertFromString(thicknessStr);
            }
            return null;
        }

        public RT.ValueNode ConvertBack(ConvertContext context, object value, object dtTagData)
        {
            RT.ValueNode vNode = new RT.ValueNode("Thickness");
            vNode.Attributes = new Dictionary<string, string>();
            System.Windows.ThicknessConverter tc = new System.Windows.ThicknessConverter();
            
            vNode.Attributes.Add("Value",tc.ConvertToString(value));

            return vNode;
        }
    }
}
